.\" $OpenBSD: EVP_MD_nid.3,v 1.4 2024/03/05 17:21:40 tb Exp $
.\" full merge up to: OpenSSL man3/EVP_DigestInit.pod
.\" 24a535ea Sep 22 13:14:20 2020 +0100
.\"
.\" This file is a derived work.
.\" The changes are covered by the following Copyright and license:
.\"
.\" Copyright (c) 2023 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>
.\" and Antoine Salon <asalon@vmware.com>.
.\" Copyright (c) 2000, 2012, 2019 The OpenSSL Project.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in
.\"    the documentation and/or other materials provided with the
.\"    distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\"    software must display the following acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\"    endorse or promote products derived from this software without
.\"    prior written permission. For written permission, please contact
.\"    openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\"    nor may "OpenSSL" appear in their names without prior written
.\"    permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\"    acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: March 5 2024 $
.Dt EVP_MD_NID 3
.Os
.Sh NAME
.Nm EVP_MD_nid ,
.Nm EVP_MD_type ,
.Nm EVP_MD_CTX_type ,
.Nm EVP_MD_name ,
.Nm EVP_MD_size ,
.Nm EVP_MD_CTX_size ,
.Nm EVP_MD_block_size ,
.Nm EVP_MD_CTX_block_size ,
.Nm EVP_MD_flags ,
.Nm EVP_MD_pkey_type
.Nd inspect EVP_MD objects
.Sh SYNOPSIS
.In openssl/evp.h
.Ft int
.Fo EVP_MD_nid
.Fa "const EVP_MD *md"
.Fc
.Ft int
.Fo EVP_MD_type
.Fa "const EVP_MD *md"
.Fc
.Ft int
.Fo EVP_MD_CTX_type
.Fa "const EVP_MD_CTX *ctx"
.Fc
.Ft const char *
.Fo EVP_MD_name
.Fa "const EVP_MD *md"
.Fc
.Ft int
.Fo EVP_MD_size
.Fa "const EVP_MD *md"
.Fc
.Ft int
.Fo EVP_MD_CTX_size
.Fa "const EVP_MD_CTX *ctx"
.Fc
.Ft int
.Fo EVP_MD_block_size
.Fa "const EVP_MD *md"
.Fc
.Ft int
.Fo EVP_MD_CTX_block_size
.Fa "const EVP_MD_CTX *ctx"
.Fc
.Ft unsigned long
.Fo EVP_MD_flags
.Fa "const EVP_MD *md"
.Fc
.Ft int
.Fo EVP_MD_pkey_type
.Fa "const EVP_MD *md"
.Fc
.Sh DESCRIPTION
.Fn EVP_MD_nid
and
.Fn EVP_MD_type
are identical and return the numerical identifier (NID) of
.Fa md .
The NID is an internal value which may or may not have
a corresponding ASN.1 OBJECT IDENTIFIER; see
.Xr OBJ_nid2obj 3
for details.
For example ,
.Fn EVP_MD_type EVP_sha512()
returns
.Dv NID_sha512 .
.Fn EVP_MD_CTX_type
returns the NID of the message digest algorithm that
.Fa ctx
is configured to use.
These functions are normally used when setting ASN.1 OIDs.
.Pp
.Fn EVP_MD_name
converts the NID of
.Fa md
to its short name with
.Xr OBJ_nid2sn 3 .
.Pp
.Fn EVP_MD_size
returns the size in bytes of the message digests (hashes) produced by
.Fa md .
.Fn EVP_MD_CTX_size
return the size of the hashes produced by the message digest algorithm that
.Fa ctx
is configured to use.
.Pp
.Fn EVP_MD_block_size
returns the block size in bytes of
.Fa md .
.Fn EVP_MD_CTX_block_size
returns the block size of the message digest algorithm that
.Fa ctx
is configured to use.
.Pp
.Fn EVP_MD_flags
returns the message digest flags used by
.Fa md .
Be careful to not confuse these flags with the unrelated
message digest context flags that can be inspected with
.Xr EVP_MD_CTX_test_flags 3 .
The available flags are:
.Bl -tag -width Ds
.It Dv EVP_MD_FLAG_DIGALGID_NULL
The parameters in a
.Vt DigestAlgorithmIdentifier
are encoded using an explicit ASN.1
.Dv NULL
rather than omitting them.
This is the default, which means that it takes effect for
.Vt EVP_MD
objects that do not have
.Dv EVP_MD_FLAG_DIGALGID_ABSENT
set.
.It Dv EVP_MD_FLAG_DIGALGID_ABSENT
The parameters in a
.Vt DigestAlgorithmIdentifier
are omitted from the ASN.1 encoding.
This is used by the
.Vt EVP_MD
objects documented in the manual page
.Xr EVP_sha3_224 3
and by the objects returned from
.Xr EVP_sha512 3 ,
.Xr EVP_sha512_256 3 ,
.Xr EVP_sha512_224 3 ,
.Xr EVP_sha384 3 ,
.Xr EVP_sha256 3 ,
.Xr EVP_sha224 3 ,
.Xr EVP_sha1 3 ,
and
.Xr EVP_sm3 3 .
.It Dv EVP_MD_FLAG_DIGALGID_CUSTOM
This flag is reserved for user-defined
.Vt EVP_MD
objects supporting custom
.Vt DigestAlgorithmIdentifier
handling via
.Xr EVP_MD_CTX_ctrl 3 ,
but actually, it is ignored by both LibreSSL and OpenSSL
and such user-defined behaviour is not supported by the libraries.
.It Dv EVP_MD_FLAG_FIPS
Mark the digest method as suitable for FIPS mode.
This flag is ignored by both LibreSSL and OpenSSL.
.It Dv EVP_MD_FLAG_ONESHOT
Intended to indicate that the digest method can only handle one block
of input, but actually, this flag is ignored by both LibreSSL and OpenSSL.
.El
.Pp
.Fn EVP_MD_pkey_type
returns the NID of the public key signing algorithm associated with this
digest.
For example,
.Xr EVP_sha512 3
is associated with RSA, so this returns
.Dv NID_sha512WithRSAEncryption .
Since digests and signature algorithms are no longer linked, this
function is only retained for compatibility reasons.
.Pp
.Fn EVP_MD_nid ,
.Fn EVP_MD_CTX_type ,
.Fn EVP_MD_name ,
.Fn EVP_MD_CTX_size ,
and
.Fn EVP_MD_CTX_block_size
are implemented as macros.
.Sh RETURN VALUES
.Fn EVP_MD_nid ,
.Fn EVP_MD_type ,
.Fn EVP_MD_CTX_type ,
and
.Fn EVP_MD_pkey_type
return the NID of the corresponding OBJECT IDENTIFIER or
.Dv NID_undef
if none exists.
.Pp
.Fn EVP_MD_name
returns a pointer to a string
that is owned by an internal library object or
.Dv NULL
if the NID is neither built into the library nor added to the global
object table by one of the functions documented in the manual page
.Xr OBJ_create 3 ,
or if the object does not contain a short name.
.Pp
.Fn EVP_MD_size ,
.Fn EVP_MD_CTX_size ,
.Fn EVP_MD_block_size ,
and
.Fn EVP_MD_CTX_block_size
return the digest or block size in bytes.
.Sh SEE ALSO
.Xr evp 3 ,
.Xr EVP_DigestInit 3 ,
.Xr EVP_MD_CTX_ctrl 3 ,
.Xr OBJ_nid2obj 3
.Sh STANDARDS
RFC 5754: Using SHA2 Algorithms with Cryptographic Message Syntax
.Bl -dash -compact -offset indent
.It
section 2: Message Digest Algorithms
.El
.Sh HISTORY
.Fn EVP_MD_size
first appeared in SSLeay 0.6.6,
.Fn EVP_MD_CTX_size
and
.Fn EVP_MD_CTX_type
in SSLeay 0.8.0,
.Fn EVP_MD_type
and
.Fn EVP_MD_pkey_type
in SSLeay 0.8.1, and
.Fn EVP_MD_block_size
and
.Fn EVP_MD_CTX_block_size
in SSLeay 0.9.0.
All these functions have been available since
.Ox 2.4 .
.Pp
.Fn EVP_MD_nid
and
.Fn EVP_MD_name
first appeared in OpenSSL 0.9.7 and have been available since
.Ox 3.2 .
.Pp
.Fn EVP_MD_flags
first appeared in OpenSSL 1.0.0
and has been available since
.Ox 4.9 .
.Sh CAVEATS
The behaviour of the functions taking an
.Vt EVP_MD_CTX
argument is undefined if they are called on a
.Fa ctx
that has no message digest configured yet,
for example one freshly returned from
.Xr EVP_MD_CTX_new 3 .
In that case, the program may for example be terminated by a
.Dv NULL
pointer access.
